package com.five.welcome.utils;

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.Random;

/**
 * @author Ywt
 * 生成订单号
 */
public class OrderIdUtils {
    //时间格式
    private static final String DATE_FORMAT = "yyyyMMddHHmmss";
    //默认前缀
    private static final String DEFAULT_PREFIX = "ORD";
    //默认后缀
    private static final String DEFAULT_SUFFIX = "";

    private static final DateTimeFormatter dateTimeFormatter
            = DateTimeFormatter.ofPattern(DATE_FORMAT);

    public static String generateOrderNumber() {
        StringBuilder orderNumber = new StringBuilder();
        orderNumber.append(DEFAULT_PREFIX);
        orderNumber.append(LocalDateTime.now().format(dateTimeFormatter));
        orderNumber.append(DEFAULT_SUFFIX);
        return orderNumber.toString();
    }
}
